package controller;

  
        

        import .entity.TStorage;
import .service.TStorageService;
import .mapper.TStorageMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rjkf.wj.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * TStorageController(TStorage)
 * @author wj
 * @since 2024-09-24 19:45:33
 */
@Api(tags={"TStorage"})
@RestController
@RequestMapping("tStorage")
public class TStorageController {

/**
 * 服务对象
 */
@Autowired
private TStorageService tStorageService;
@Resource
private TStorageMapper tStorageMapper;
/**
 * 分页查询所有数据
 * @param tStorage 查询实体
 * @return 所有数据
 */
@ApiOperation("分页查询所有数据")
@PostMapping("/list")
public Result selectAll(@RequestBody TStorage tStorage) {
        QueryWrapper<TStorage> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("time");
        Page<TStorage> page = new Page<>(tStorage.getPageNo(), tStorage.getPageSize());
        IPage<TStorage> pageList = tStorageService.page(page, queryWrapper);
        return Result.success("查询成功", pageList);
        }

/**
 * 通过主键查询单条数据
 *
 * @param id 主键
 * @return 单条数据
 */
@ApiOperation("通过主键查询单条数据")
@GetMapping("getById/{id}")
public Result selectOne(@PathVariable Serializable id) {
        return Result.success("查询成功", tStorageService.getById(id));
        }

/**
 * 新增数据
 *
 * @param tStorage 实体对象
 * @return 新增结果
 */
@ApiOperation("新增数据")
@PostMapping("/insert")
public Result insert(@RequestBody TStorage tStorage) {
        boolean rs = tStorageService.save(tStorage);
        if (rs) {
        return Result.success("添加成功", "");
        } else {
        return Result.error("添加失败");
        }
        }

/**
 * 修改数据
 *
 * @param tStorage 实体对象
 * @return 修改结果
 */
@ApiOperation("修改数据")
@PostMapping("/update")
public Result update(@RequestBody TStorage tStorage) {
        tStorageService.updateById(tStorage);
        return Result.success("修改成功","");
        }

/**
 * 批量删除数据
 *
 * @param idList 主键集合
 * @return 删除结果
 */
@ApiOperation("批量删除数据")
@PostMapping("/delete")
public Result delete(@RequestParam("idList") List<Serializable> idList) {
        int result = 0;
        if (idList!=null&&idList.size()>0) {
        tStorageService.removeByIds(idList);
        };
        return Result.success("删除成功","");
        }

/**
 * 批量删除数据
 *
 * @param id 主键
 * @return 删除结果
 */
@ApiOperation("单个删除数据")
@PostMapping("/delete/{id}")
public Result delete(@PathVariable Serializable id) {
        tStorageService.removeById(id);
        return Result.success("删除成功","");
        }
        }
